package com.quasar.hpatient.network;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * author : 许建宏
 * Date: 2017/9/26 0026
 * View:
 */

public class RetrofitConnection {

    //124.232.150.34
    //39.104.68.161
    private static OkHttpClient okHttpClient = new OkHttpClient.Builder()
            . connectTimeout(1000, TimeUnit.SECONDS).
                    readTimeout(1000, TimeUnit.SECONDS).
                    writeTimeout(1000, TimeUnit.SECONDS).build();


    private static String BasicDataUrls="http://api.onequasar.com/com.czxx.springmvc.frame/";//http://192.168.1.168:8080/com.czxx.springmvc.frame/
    public static String RoutineUrls="http://www.onequasar.com/api/";//http://124.232.150.34:18182/api/
    //图片地址
    public static String PHOTOURL="http://www.onequasar.com/uploads/";
    private static ApiService apiService;
    //数据转换成json形式
    private static Converter.Factory gsonConverterFactory = GsonConverterFactory.create();

    //获取基础库
    public static ApiService getBasicDataUrls(){

        Retrofit retrofit=new Retrofit.Builder()
                .client(okHttpClient)
                .baseUrl(RoutineUrls)
                .addConverterFactory(gsonConverterFactory)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();

        apiService=retrofit.create(ApiService.class);
        return apiService;
    }

    //常规数据请求
    public static ApiService getRoutineApi(){
        Retrofit retrofit=new Retrofit.Builder()
                .client(okHttpClient)
                .baseUrl(BasicDataUrls)
                .addConverterFactory(gsonConverterFactory)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();

        apiService=retrofit.create(ApiService.class);
        return apiService;
    }

    //下载图片
    public static ApiService getPhotoDown(){
        Retrofit retrofit=new Retrofit.Builder()
                .client(okHttpClient)
                .baseUrl(PHOTOURL)
                .addConverterFactory(gsonConverterFactory)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();

        apiService=retrofit.create(ApiService.class);
        return apiService;
    }

}
